<?php
/**
 * GioCMS
 * 
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2 
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@ninhgio.com so we can send you a copy immediately.
 * 
 * @copyright	Copyright (c) 2010-2011 GioCMS (http://cms.ninhgio.com)
 * @license		http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 * @author		NinhGio - ninhgio@gmail.com
 * @since		1.0
 */

class Modules_Core_Models_Mysql_Controller extends Modules_Core_Models_Controller
{
	public function dbControllers($module = null)
	{
		$sql = 'SELECT * FROM ' . $this->_conn->_tablePrefix . 'core_controller';
		if ($module) {
			$sql .= ' WHERE module_id = "' . $this->_conn->escape($module) . '"';
		} 
		$sql .= ' ORDER BY controller_id ASC';
		$rs = $this->_conn->query($sql);
		$controllers = array();
		while ($row = $this->_conn->fetchAll($rs)) {
			$controllers[] = $row;
		}
		/**
		 * Free result 
		 */
		$this->_conn->freeResult($rs);
		return $controllers;
	}
	
	public function add($controller)
	{
		$this->_conn->insert($controller, $this->_conn->_tablePrefix . 'core_controller');
	}
	
	public function delete($moduleId, $controllerId)
	{
		$sql = 'DELETE FROM ' . $this->_conn->_tablePrefix . 'core_controller 
							WHERE module_id = "' . $this->_conn->escape($moduleId) . '" AND controller_id = "' . $this->_conn->escape($controllerId) . '"';
		$rs = $this->_conn->query($sql);
		$affectRow = $this->_conn->affectedRows();
		$this->_conn->freeResult($rs);
		return $affectRow;
	}
}